

const mongoose = require("mongoose")

//如果数据不存会自动创建数据库
mongoose.connect("mongodb://127.0.0.1:27017/testDB")

const db = mongoose.connection;
db.on('error', console.error.bind(console, 'Connection error:'));
db.once('open', () => console.log('Connected to MongoDB via Mongoose'));